package com.crazyandroid.view;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.Toast;

import com.crazyandroid.R;

public class ViewTest extends Activity
{
	Button btn;
	EditText et1,et2,et3;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.patch9layout);
	}
/*
		btn = (Button) findViewById(R.id.btnReg);

		btn.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View arg0)
			{
				// TODO Auto-generated method stub
				// setContentView(R.layout.userview);
				Method1(R.layout.userview);
				TableLayout l=(TableLayout)findViewById(R.id.tuv);
//				l.setOnClickListener(new OnClickListener()
//				{
//					
//					@Override
//					public void onClick(View v)
//					{
//						InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//						if (imm != null) {
//							imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
//						}
//					}
//				});
				l.setOnTouchListener(new OnTouchListener()
				{
					
					@Override
					public boolean onTouch(View v, MotionEvent event)
					{
						// TODO Auto-generated method stub
						InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
						if (imm != null) {
							imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
							v.clearFocus();
						}
						return true;
					}
				});
				et1=(EditText) findViewById(R.id.editName);
				et2=(EditText) findViewById(R.id.pwd);
				et3=(EditText) findViewById(R.id.phone);
				
//				if(null!=et1&&null!=et2&&null!=et3)
//				{
//					et1.setOnFocusChangeListener(new EditChange());
//					et2.setOnFocusChangeListener(new EditChange());
//					et3.setOnFocusChangeListener(new EditChange());
//				}
			}
		});

		
		
	}

	protected void Method1(int view)
	{
		this.setContentView(view);
		btn = (Button) findViewById(R.id.btnShow);
		btn.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				
				String edit = et1.getText().toString();
				String pwd = et2.getText().toString();
				String phone = et3.getText().toString();
				Toast toast = Toast.makeText(ViewTest.this, edit+":"+pwd+":"+phone,
						Toast.LENGTH_SHORT);
				toast.show();
			}
		});
	}
	
	public class EditChange implements OnFocusChangeListener
	{
		
		@Override
		public void onFocusChange(View v, boolean hasFocus)
		{
			InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
			if (imm != null&&!hasFocus) {
				imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
				v.clearFocus();
			}
			if(!hasFocus)
			{
				v.clearFocus();
			}
//			Toast toast = Toast.makeText(ViewTest.this, String.valueOf(v.getId())+":"+String.valueOf(hasFocus),
//					Toast.LENGTH_SHORT);
//			toast.show();
		}
	}
	
	*/
}
